<template>
    <rx-layout>
        <div slot="center" style>
            <rx-fit>
                <div slot="toolheader" foldheader="true" foldbtn="false" border="false">
                    <div class="table-operator">
                        <a-button  type="primary" icon="plus" @click="add">
                            {{$ti18('rxList.newBtn','新建')}}
                        </a-button>
                        <a-dropdown v-if="editEnable && selectedRowKeys.length > 0 || removeEnable && selectedRowKeys.length > 0">
                            <a-button style="margin-left: 8px">
                                {{$ti18('rxList.moreBtn','更多')}}
                            <a-icon type="down" /> </a-button>
                            <a-menu slot="overlay">
                                <a-menu-item key="1" v-if="editEnable && selectedRowKeys.length > 0" alias="formEntityDataTypeEdit" :butn-icon="'edit'"
                                             :butn-type="'primary'" :show-no-right="false" @click="editOne"><a-icon type="user"  />
                                    {{$ti18('rxList.editBtn','编辑')}}
                                </a-menu-item>
                                <a-menu-item key="2" v-if="removeEnable && selectedRowKeys.length > 0" alias="formEntityDataTypeDelete" :butn-icon="'delete'" :butn-type="'danger'"
                                             :show-no-right="false" @click="delByIds(selectedRowKeys)"><a-icon type="delete" />
                                    {{$ti18('rxList.delBtn',"删除")}}
                                </a-menu-item>
                                <a-menu-item
                                    key="3"
                                    @click="changeExport(exportConf)"
                                    v-if="selectedRowKeys.length > 0"
                                    alias="formRuleDelete"
                                    :butn-type="'primary'"
                                    :show-no-right="false"
                                >
                                    <a-icon type="switcher"/>
                                    {{$ti18('rxList.changeExport','切换导出')}}
                                </a-menu-item>
                            </a-menu>
                        </a-dropdown>
                    </div>
                    <span class="search-btn-box">
                <span class="search-btn" @click="searchshow"><i class="iconfont iconguolv"></i>
                {{$ti18('rxList.leachBtn','过滤')}}
                </span>
           </span>
                </div>
                <div slot="searchbar" btnalign="right"  v-if="fitSearch" @search="search" @cancel="cancel" @close="close">
                    <a-form layout="vertical">
                        <a-form-item :label="$comi18('rxDialog.typeName', '类型名称')">
                            <a-input :placeholder="$comi18('rxDialog.typeName', '请输入类型名称','input')" v-model="queryParam.Q_NAME__S_LK"/>
                        </a-form-item>
                        <a-col :span="colSpan" v-if="!curApp.appId">
                            <a-form-item :label="$ti18('rxForm.appId', '应用')">
                                <rx-search-app @change="appChange" v-model="searchApps">
                                </rx-search-app>
                            </a-form-item>
                        </a-col>
                    </a-form>
                </div>
                <rx-grid
                    ref="table"
                    :allowRowSelect="true"
                    :multiSelect="true"
                    :columns="columns"
                    :bordered="isBorder"
                    :defaultPageSize="10"
                    url="/api-form/form/core/formEntityDataType/query"
                    :queryParam="queryParam"
                    data-field="result.data"
                    :pageSizeOptions="['10','30','40']"
                    id-field="id"
                    @selectChange="onSelectChange"
                >
                    <span slot="exportApp">
                         {{ exportI18n('export.isExport','导出') }}
                        <export-app/>
                    </span>
            <span slot="dataShowType" slot-scope="{ text, record }">
            <a-tag v-if="text" :color="dataShowTypeMap[text].color">
              <span>{{ dataShowTypeMap[text].text }}</span>
            </a-tag>
            <a-tag v-else :color="dataShowTypeMap['FLAT'].color">
                <span>{{ dataShowTypeMap['FLAT'].text }}</span>
            </a-tag>
          </span>
                    <span slot="status" slot-scope="{ text, record }">
            <a-tag :color="statusMap[text].color">
              <span>{{ statusMap[text].text }}</span>
            </a-tag>
          </span>
            <span slot="appId" slot-scope="{ text, record }">
                {{allApps[text]?$i18(allApps[text].appName,'应用名称'):$ti18('rxList.noAppName','无')}}
            </span>
            <span slot="isExport" slot-scope="{ text, record }">
                <a-tag :color="text == 1 ? 'green' : 'red'">
                    <span>{{ text == 1 ? exportI18n('export.yes','是') : exportI18n('export.no','否') }}</span>
                </a-tag>
            </span>
            <span slot="action" slot-scope="{ text, record }" class="actionIcons">
                <span v-if="editEnable" @click.stop="edit(record)">
                    {{$ti18('rxList.editBtn',"编辑")}}
                </span>
                <span v-if="removeEnable" @click.stop="delByIds([record.id])">
                    {{$ti18('rxList.delBtn','删除')}}
                </span>
                <span @click="setExport(record,exportConf)">{{record.isExport == 1 ? exportI18n('export.noExport','不导出') : exportI18n('export.exported','导出')}}</span>
            </span>
                </rx-grid>
            </rx-fit>
        </div>
    </rx-layout>
</template>

<script>
    import FormEntityDataTypeApi from '@/api/form/core/formEntityDataType'
    import FormEntityDataTypeEdit from './FormEntityDataTypeEdit'
    import {BaseList,RxFit,RxGrid } from "@lowcode/jpaas-common-lib";
    import {mapState} from "vuex";
    import exportApp from "@/views/modules/share/exportApp";
    import SysAppApi from "@/api/system/core/sysApp";
    import AppSearch from "@/views/modules/share/AppSearch";
    import RxSearchApp from "@/views/modules/share/rx-search-app";
    import switchExport from "@/utils/switchExport";
    export default {
        name: 'FormEntityDataTypeList',
        mixins: [BaseList,AppSearch,switchExport],
        components: {
            RxFit,
            exportApp,
            RxSearchApp
        },
        computed: {
            ...mapState({
                //所属应用
                allApps: state => state.appSetting ? state.appSetting.allApps : {}
            }),
        },
        data() {
            return {
                columns: [
                    {
                        title: this.$ti18('rxList.index','序号'),
                        type: 'indexColumn',
                        width: 40,
                        dataIndex: 'serial',
                        scopedSlots: {customRender: 'serial'}
                    },
                    {title: this.i18n('form.typeName','类型名称'), dataIndex: 'name', width: 120},
                    {title: this.i18n('form.displayMethod','展示方式'), dataIndex: 'dataShowType', width: 100, scopedSlots: {customRender: 'dataShowType'}},
                    {title: this.i18n('form.status','状态'), dataIndex: 'status', width: 60, scopedSlots: {customRender: 'status'}},
                    {title: this.i18n('form.application','所属应用'), dataIndex: 'appId', width: 100, sortField: 'APP_ID_',scopedSlots: {customRender: 'appId'}},
                    {
                        dataIndex: 'isExport',
                        slots: { title: 'exportApp' },
                        width: 60,
                        scopedSlots: {customRender: 'isExport'}
                    },
                    {title: this.$ti18('rxForm.createTime','创建时间'), dataIndex: 'createTime',  width: 120},
                    {title: this.$ti18('rxList.action','操作'), width: 100, dataIndex: 'action',scopedSlots: {customRender: 'action'}}
                ],
                statusMap: {
                    'ENABLED': { color: 'green', text: this.i18n('isStatusMap.enabled','启用') },
                    'DISABLED': { color: 'red', text: this.i18n('isStatusMap.disabled','禁用')},
                },
                dataShowTypeMap:{
                    'FLAT': { color: 'blue', text: this.i18n('isDataShowTypeMap.enabled','平铺') },
                    'TREE': { color: 'green', text: this.i18n('isDataShowTypeMap.treeForm','树形') }
                },
                component:FormEntityDataTypeEdit,
                comment:this.i18n('list.comment','业务实体数据类型'),
                widthHeight:['800px','600px'],
                fitSearch:false,
                //应用列表
                appList:[],
                loading:false,
                //选择的应用
                selectedApp:[],
                /**
                 * 导出配置
                 */
                exportConf:{
                    Api:FormEntityDataTypeApi,
                    id:"id"
                }
            }
        },
        created() {
            this.needFilterAppId();
            this.columns=this.removeAppColumn(this.curApp.appId,this.columns)
        },
        methods:{
            i18n(name,text,key){
                return this.$ti18(name,text,"formEntityDataType",key);
            },
            exportI18n(name,text,key){
                return this.$ti18(name,text,"appExport",key);
            },

            //fsad
            delById(ids){
                return FormEntityDataTypeApi.del({ ids: ids.join(',') });
            },
            getListByParams(parameter){
                return FormEntityDataTypeApi.query(parameter)
            },
            search(){
                this.$refs.table.loadData()
            },
            cancel(){
                this.resetSearch();
                this.selectedApp = [];
            },
            close(){
                //关闭按钮
                this.fitSearch = false ;
            },
        }
    }
</script>
<style scoped>

</style>

